<template>
  <button
    @click="sendClick"
    :disabled="disabled"
    class="button"
    :class="[`button-${type}`, {'plain':plain}, {'round': round}, {'circle': circle}, {'disabled': disabled}]">
    <i v-if="iconPos === 'left'" :class="[`icon-${icon}`]"></i>
    <!-- 插槽没给值是空时不显示 span -->
    <span v-if="$slots.default">
      <!-- slot 给父组件传过来的值预留展示空间 -->
      <slot></slot>
    </span>
    <i v-if="iconPos === 'right'" :class="[`icon-${icon}`]"></i>
  </button>
</template>
<script>
export default {
  name: 's-button',
  // 数组类型的 props 比较宽松，所以需要使用对象，有类型校验
  props: {
    type: {
      type: String,
      default: 'default'
    },
    plain: {
      type: Boolean,
      default: false
    },
    round: {
      type: Boolean,
      defalut: false
    },
    circle: {
      type: Boolean,
      defalut: false
    },
    icon: {
      type: String,
      defalut: ''
    },
    iconPos: {
      type: String,
      default: 'left'
    },
    disabled: {
      type: Boolean,
      defalut: 'default'
    }
  },
  data () {
    return {
    }
  },
  methods: {
    sendClick () {
      this.$emit('click')
    }
  },
  computed: {
  }
}
</script>
<style lang='scss' scoped>
// 全局样式
.button {
  width: 100px;
  height: 40px;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  color: #606266;
  cursor: pointer;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 10px;
  transition: 0.1s;
  font-weight: 500;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  font-size: 14px;
  &:hover,
  &:focus {
    color: #409eff;
    border-color: #c6e2ff;
    background-color: #ecf5ff;
  }
}

// 基本样式
.button-primary {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
  &:hover,
  &:focus {
    background: #66b1ff;
    border-color: #66b1ff;
    color: #fff;
  }
}

.button-success {
  color: #fff;
  background-color: #67c23a;
  border-color: #67c23a;
  &:hover,
  &:focus {
    background: #85ce61;
    border-color: #85ce61;
    color: #fff;
  }
}

.button-info {
  color: #fff;
  background-color: #909399;
  border-color: #909399;
  &:hover,
  &:focus {
    background: #a6a9ad;
    border-color: #a6a9ad;
    color: #fff;
  }
}

.button-warning {
  color: #fff;
  background-color: #e6a23c;
  border-color: #e6a23c;
  &:hover,
  &:focus {
    background: #ebb563;
    border-color: #ebb563;
    color: #fff;
  }
}

.button-danger {
  color: #fff;
  background-color: #f56c6c;
  border-color: #f56c6c;
  &:hover,
  &:focus {
    background: #f78989;
    border-color: #f78989;
    color: #fff;
  }
}

// 朴素按钮样式 plain
.button.plain {
  color: #606266;
  background-color: #fff;
  border-color: #dcdfe6;
  &:hover,
  &:focus {
    background-color: #fff;
    border-color: #409eff;
    color: #409eff;
  }
}

.button-primary.plain {
  color: #409eff;
  background: #ecf5ff;
  border-color: #b3d8ff;
  &:hover,
  &:focus {
    background-color: #409eff;
    border-color: #409eff;
    color: #fff;
  }
}

.button-success.plain {
  color: #67c23a;
  background: #f0f9eb;
  border-color: #c2e7b0;
  &:hover,
  &:focus {
    background-color: #67c23a;
    border-color: #67c23a;
    color: #fff;
  }
}

.button-info.plain {
  color: #909399;
  background-color: #f4f4f5;
  border-color: #d3d4d6;
  &:hover,
  &:focus {
    background: #909399;
    border-color: #909399;
    color: #fff;
  }
}

.button-warning.plain {
  color: #e6a23c;
  background-color: #fdf6ec;
  border-color: #f5dab1;
  &:hover,
  &:focus {
    background: #e6a23c;
    border-color: #e6a23c;
    color: #fff;
  }
}

.button-danger.plain {
  color: #f56c6c;
  background-color: #fef0f0;
  border-color: #fbc4c4;
  &:hover,
  &:focus {
    background: #f56c6c;
    border-color: #f56c6c;
    color: #fff;
  }
}

// 圆角样式 round
.button.round {
  border-radius: 20px;
}

.button-primary.round {
  border-radius: 20px;
}

.button-success.round {
  border-radius: 20px;
}

.button-info.round {
  border-radius: 20px;
}

.button-warning.round {
  border-radius: 20px;
}

.button-danger.round {
  border-radius: 20px;
}

// 圆形样式 circle
.button.circle {
  border-radius: 50%;
}

.button-primary.circle {
  border-radius: 50%;
}

.button-success.circle {
  border-radius: 50%;
}

.button-info.circle {
  border-radius: 50%;
}

.button-warning.circle {
  border-radius: 50%;
}

.button-danger.circle {
  border-radius: 50%;
}

// 基本按钮禁用样式 disabled
.button.disabled {
  color: #c0c4cc;
  background-color: #fff;
  border-color: #ebeef5;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}
.button-primary.disabled {
  color: #fff;
  background-color: #a0cfff;
  border-color: #a0cfff;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-success.disabled {
  color: #fff;
  background-color: #b3e19d;
  border-color: #b3e19d;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-info.disabled {
  color: #fff;
  background-color: #c8c9cc;
  border-color: #c8c9cc;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-warning.disabled {
  color: #fff;
  background-color: #f3d19e;
  border-color: #f3d19e;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-danger.disabled {
  color: #fff;
  background-color: #fab6b6;
  border-color: #fab6b6;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

// 镂空按钮禁用样式
.button.plain.disabled {
  background-color: #fff;
  border-color: #ebeef5;
  color: #c0c4cc;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-primary.plain.disabled {
  color: #8cc5ff;
  background-color: #ecf5ff;
  border-color: #d9ecff;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-success.plain.disabled {
  color: #a4da89;
  background-color: #f0f9eb;
  border-color: #e1f3d8;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-info.plain.disabled {
  color: #bcbec2;
  background-color: #f4f4f5;
  border-color: #e9e9eb;
  &:hover,
  &:focus {
    cursor: not-allowed;

  }
}

.button-warning.plain.disabled {
  color: #f0c78a;
  background-color: #fdf6ec;
  border-color: #faecd8;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

.button-danger.plain.disabled {
  color: #f9a7a7;
  background-color: #fef0f0;
  border-color: #fde2e2;
  &:hover,
  &:focus {
    cursor: not-allowed;
  }
}

// span 有值时左侧边距 + 5px
.button span {
  margin-left: 5px;
  margin-right: 5px;
}
</style>
